package com.example.demo.dao;

import com.example.demo.Enity.privateTalk;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.ArrayList;

public interface MyInfoJpa extends JpaRepository<privateTalk, Integer>, JpaSpecificationExecutor<privateTalk> {
/*查看用户名*/

//查看该用户名是否存在(输入用户id)
@Query(nativeQuery = true,value = "select count(*) from user where yb_userid='11223344'")
public int userIsExist(String userid);

//获取用户名
@Query(nativeQuery = true,value = "select yb_usernick from user where yb_userid=?1")
String getNickName(String yb_userid);

//修改用户名(输入用户id)
@Modifying
@Transactional
@Query(nativeQuery = true,value = "update user set yb_usernick=?2 where yb_userid=?1")
void setNickName(String yb_userid,String name);
/*我的发布*/

//查看自己发布的活动(输入用户id)
@Query(nativeQuery = true,value = "select * from activity where ided=?1")
ArrayList getMineActivity(String userid);

//删除活动(输入活动id和用户id)
@Modifying
@Transactional
@Query(nativeQuery = true,value = "delete from activity where id=?1 and ided=?2")
void deleteMineActivity(String actid,String userid);

//活动信息(输入活动id)
@Query(nativeQuery = true,value = "select * from activity where id=?1 and ided=?2")
ArrayList getActivityInfo(String actid,String userid);


/*我关注的活动*/

//我的关注(输入用户id)
@Query(nativeQuery = true,value = "select A.id,A.address,A.category,A.ided,A.img,A.information,A.master,A.time,A.wx,U.yb_userhead from relate R join activity A on R.avid=A.id join user U on A.ided=U.yb_userid where R.ided=?1")
ArrayList getMyFavourite(String userid);

//取消关注(输入活动id和用户id)
@Modifying
@Transactional
@Query(nativeQuery = true,value = "delete from relate where avid=?1 and ided=?2")
void deleteMyFavourite(String actid,String userid);

}
